package com.example.flowengine;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.japi.pf.FI;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

/**
 * @author daxue0929
 * @date 2023/1/6
 */

public class HelloWord {


    //定义一个Actor
    static class ActorDemo extends AbstractActor{

        public void start(String msg) {
            System.out.println(Thread.currentThread().getName()
                + ": ActorDemo match String receive enter is: " + msg);
        }


        @Override
        public Receive createReceive() {
            return receiveBuilder().match(String.class, new FI.UnitApply<String>() {
                @Override
                public void apply(String msg) throws Exception {
                    start(msg);
                }
            }).build();
        }
    }
    /**
     * 一个系统中可以有很多Actor
     */


    @Test
    public void main() throws InterruptedException {
        System.out.println(Thread.currentThread().getName());
        ActorSystem system = ActorSystem.create("sys");

        // 返回一个Actor引用
        ActorRef actorDemoRef = system.actorOf(Props.create(ActorDemo.class), "actorDemo");
        actorDemoRef.tell("ai ni you", ActorRef.noSender());


        //这里可能是因为启动的是Test线程，然后线程就直接结束了，所以这里睡眠3秒不让test线程结束。
        Thread.sleep(3000);
    }


    @Test
    public void jsonTest() {
        String graphic = "{\"edges\":[{\"targetAnchor\":1,\"forwardConfig\":{\"label\":\"全部\"},\"tipCircle\":{\"color\":\"#327DE8\"},\"sourceAnchor\":3,\"target\":\"f71faee1\",\"index\":1,\"source\":\"559f9db3\",\"id\":\"cb3c80a3\",\"forwardType\":\"ALL\"},{\"targetAnchor\":1,\"forwardConfig\":{\"label\":\"符合分支条件\",\"logic\":\"\"},\"tipCircle\":{\"color\":\"#43AA4D\"},\"sourceAnchor\":3,\"target\":\"e2d5582c\",\"index\":2,\"source\":\"f71faee1\",\"id\":\"6b3df84f\",\"forwardType\":\"PROCESSED\"},{\"targetAnchor\":1,\"forwardConfig\":{\"label\":\"全部\",\"logic\":\"\"},\"tipCircle\":{\"color\":\"#327DE8\"},\"sourceAnchor\":3,\"target\":\"869390e8\",\"index\":5,\"source\":\"e2d5582c\",\"id\":\"bb794839\",\"forwardType\":\"ALL\"},{\"targetAnchor\":1,\"forwardConfig\":{\"label\":\"无同步目标\",\"logic\":\"镜像数据有效 & 无同步目标\"},\"tipCircle\":{\"color\":\"#9E1B98\"},\"sourceAnchor\":3,\"target\":\"cbae4c50\",\"index\":6,\"source\":\"869390e8\",\"id\":\"5520e186\",\"forwardType\":\"UNPROCESSED\"},{\"targetAnchor\":1,\"forwardConfig\":{\"label\":\"创建成功\",\"logic\":\"镜像数据有效 & 无同步目标 & 输入时操作未定\"},\"tipCircle\":{\"color\":\"#43AA4D\"},\"sourceAnchor\":3,\"target\":\"f1e1f244\",\"index\":10,\"source\":\"cbae4c50\",\"id\":\"7aeb5337\",\"forwardType\":\"PROCESSED\"},{\"source\":\"f71faee1\",\"sourceAnchor\":0,\"target\":\"869390e8\",\"targetAnchor\":0,\"id\":\"a6cd32e5\",\"index\":11,\"forwardType\":\"UNPROCESSED\",\"forwardConfig\":{\"label\":\"不符合分支条件\",\"logic\":\"\"},\"tipCircle\":{\"color\":\"#9E1B98\"}}],\"nodes\":[{\"size\":\"40*40\",\"shape\":\"custom-rect\",\"imgSize\":24,\"metaConfig\":{\"name\":\"统一目录（全量）\",\"color\":\"white\",\"iconUrl\":\"images/app-logo/yufu.png\",\"config\":{\"forwardTranslation\":{\"ALL\":{\"label\":\"全部\"}}}},\"mainColor\":\"#FAFAFA\",\"index\":0,\"deletable\":false,\"borderColor\":\"#D9D9D9\",\"x\":260,\"isStart\":true,\"y\":60,\"icon\":\"https://idaas-cdn-1258344699.file.myqcloud.com/images/app-logo/yufu.png\",\"type\":\"node\",\"id\":\"559f9db3\"},{\"metaId\":\"am-split-actor-meta\",\"actorName\":\"分支\",\"size\":\"40*40\",\"shape\":\"custom-rect\",\"imgSize\":24,\"metaConfig\":{\"actorName\":\"split-actor\",\"config\":{\"forwardTranslation\":{\"PROCESSED\":{\"label\":\"符合分支条件\",\"logic\":\"\"},\"UNPROCESSED\":{\"label\":\"不符合分支条件\",\"logic\":\"\"}}},\"dynamicForm\":{\"key\":\"value\"},\"mode\":\"SYNC\",\"color\":\"#91BB2C\",\"tenantId\":\"tn-public\",\"createdOn\":\"2019-08-17T08:17:26.692+0000\",\"flowType\":\"DATA_FLOW\",\"modifiedOn\":\"2019-08-17T08:17:26.879+0000\",\"name\":\"分支\",\"code\":\"split-actor-meta\",\"actorType\":\"SPLIT\",\"status\":\"ACTIVE\",\"iconUrl\":\"lcm_actor_split.svg\",\"loadingType\":\"STATIC\",\"id\":\"am-split-actor-meta\",\"description\":\"\"},\"hasDynamicForm\":true,\"mainColor\":\"#91BB2C\",\"actorId\":\"ac-cbfe127431304e75856bb8007fd64fd0\",\"index\":3,\"borderColor\":\"\",\"x\":205.5,\"y\":144.296875,\"icon\":\"images/lcm/lcm_actor_split.svg\",\"type\":\"node\",\"id\":\"f71faee1\"},{\"metaId\":\"am-transform-actor-meta\",\"actorName\":\"转换\",\"size\":\"40*40\",\"shape\":\"custom-rect\",\"imgSize\":24,\"metaConfig\":{\"actorName\":\"transform-actor\",\"config\":{\"forwardTranslation\":{\"ALL\":{\"label\":\"全部\",\"logic\":\"\"}}},\"dynamicForm\":{\"key\":\"value\"},\"mode\":\"SYNC\",\"color\":\"#DC3333\",\"tenantId\":\"tn-public\",\"createdOn\":\"2019-08-01T08:17:26.692+0000\",\"flowType\":\"DATA_FLOW\",\"modifiedOn\":\"2019-08-17T08:17:26.879+0000\",\"name\":\"转换\",\"code\":\"transform-actor-meta\",\"actorType\":\"TRANSFORM\",\"status\":\"ACTIVE\",\"iconUrl\":\"lcm_actor_transform.svg\",\"loadingType\":\"STATIC\",\"id\":\"am-transform-actor-meta\",\"description\":\"节点输出字段=节点内转换的字段\"},\"hasDynamicForm\":true,\"mainColor\":\"#DC3333\",\"actorId\":\"ac-36cda44e02594239b05e076cac5351ea\",\"index\":4,\"borderColor\":\"\",\"x\":259.5,\"y\":230.796875,\"icon\":\"images/lcm/lcm_actor_transform.svg\",\"type\":\"node\",\"id\":\"e2d5582c\"},{\"metaId\":\"am-create-actor-meta\",\"actorName\":\"创建\",\"size\":\"40*40\",\"shape\":\"custom-rect\",\"imgSize\":24,\"metaConfig\":{\"actorName\":\"create-actor\",\"config\":{\"forwardTranslation\":{\"ALL\":{\"label\":\"全部\",\"logic\":\"\"},\"PROCESSED\":{\"label\":\"创建成功\",\"logic\":\"镜像数据有效 & 无同步目标 & 输入时操作未定\"},\"UNQUALIFIED\":{\"label\":\"无法创建\",\"logic\":\"镜像数据无效 | 有同步目标 | 输入时操作已定\"}}},\"dynamicForm\":{},\"mode\":\"SYNC\",\"color\":\"#525CDD\",\"tenantId\":\"tn-public\",\"createdOn\":\"2019-08-04T08:17:26.692+0000\",\"flowType\":\"DATA_FLOW\",\"modifiedOn\":\"2019-08-24T08:12:34.932+0000\",\"name\":\"创建\",\"code\":\"create-actor-meta\",\"actorType\":\"CREATE\",\"status\":\"ACTIVE\",\"iconUrl\":\"lcm_actor_create.svg\",\"loadingType\":\"STATIC\",\"id\":\"am-create-actor-meta\",\"description\":\"\"},\"hasDynamicForm\":false,\"mainColor\":\"#525CDD\",\"actorId\":\"ac-96ba4965e87a4ee2b5f505e4a4cecc91\",\"index\":7,\"borderColor\":\"\",\"x\":261.6,\"y\":376.85,\"icon\":\"images/lcm/lcm_actor_create.svg\",\"type\":\"node\",\"id\":\"cbae4c50\"},{\"metaId\":\"am-match-actor-meta\",\"actorName\":\"匹配\",\"size\":\"40*40\",\"shape\":\"custom-rect\",\"imgSize\":24,\"metaConfig\":{\"actorName\":\"match-actor\",\"config\":{\"forwardTranslation\":{\"ALL\":{\"label\":\"全部\",\"logic\":\"\"},\"PROCESSED\":{\"label\":\"有同步目标\",\"logic\":\"镜像数据有效 & 有同步目标\"},\"UNPROCESSED\":{\"label\":\"无同步目标\",\"logic\":\"镜像数据有效 & 无同步目标\"},\"UNQUALIFIED\":{\"label\":\"无法匹配\",\"logic\":\"镜像数据无效\"}}},\"dynamicForm\":{\"key\":\"value\"},\"mode\":\"SYNC\",\"color\":\"#A41AA1\",\"tenantId\":\"tn-public\",\"createdOn\":\"2019-08-02T08:17:26.692+0000\",\"flowType\":\"DATA_FLOW\",\"modifiedOn\":\"2019-08-24T08:11:04.863+0000\",\"name\":\"匹配\",\"code\":\"match-actor-meta\",\"actorType\":\"MATCH\",\"status\":\"ACTIVE\",\"iconUrl\":\"lcm_actor_match.svg\",\"loadingType\":\"STATIC\",\"id\":\"am-match-actor-meta\",\"description\":\"\"},\"hasDynamicForm\":true,\"mainColor\":\"#A41AA1\",\"actorId\":\"ac-d7d414721ad64aa5928bd5ce608b7bbe\",\"index\":8,\"borderColor\":\"\",\"x\":184.5,\"y\":304.35,\"icon\":\"images/lcm/lcm_actor_match.svg\",\"type\":\"node\",\"id\":\"869390e8\"},{\"metaId\":\"am-push-actor-meta\",\"actorName\":\"test\",\"size\":\"40*40\",\"shape\":\"custom-rect\",\"imgSize\":24,\"metaConfig\":{\"actorName\":\"push-actor\",\"config\":{},\"mode\":\"SYNC\",\"color\":\"#FAFAFA\",\"tenantId\":\"tn-public\",\"createdOn\":\"2019-08-17T08:17:26.692+0000\",\"flowType\":\"DATA_FLOW\",\"modifiedOn\":\"2019-08-17T08:17:26.879+0000\",\"name\":\"test\",\"code\":\"push-actor-meta\",\"actorType\":\"PUSH\",\"status\":\"ACTIVE\",\"iconUrl\":\"images/app-logo/weChatLogo.png\",\"loadingType\":\"STATIC\",\"id\":\"am-push-actor-meta\",\"description\":\"\"},\"hasDynamicForm\":false,\"mainColor\":\"#FAFAFA\",\"actorId\":\"ac-a77269fb6d28442c824b8531daec1e15\",\"isEnd\":true,\"index\":9,\"borderColor\":\"#D9D9D9\",\"x\":200.2,\"y\":452.40000000000015,\"icon\":\"images/app-logo/weChatLogo.png\",\"type\":\"node\",\"id\":\"f1e1f244\"}]}";

        JSONObject object = JSONObject.parseObject(graphic);
        System.out.println(object.toJSONString());
    }
}
